<template>
  <div class="Banner">
    <div class="swiper-container" ref="mySwiper">
      <div class="swiper-wrapper">
        <div class="swiper-slide" v-for="carousel in list" :key='carousel.id'>
          <img :src="carousel.imgUrl">
        </div>
      </div>
      <!-- 如果需要分页器 -->
      <div class="swiper-pagination"></div>

      <!-- 如果需要导航按钮 -->
      <div class="swiper-button-prev"></div>
      <div class="swiper-button-next"></div>
    </div>
  </div>
</template>

<script>
import Swiper from 'swiper'
import 'swiper/css/swiper.css'
export default {
  // 组件名称
  name: 'Carousel',
  // 组件参数 接收来自父组件的数据
  props: ['list'],
  // 局部注册的组件
  components: {},
  // 组件状态值
  data() {
    return {}
  },
  // 计算属性
  computed: {},
  // 侦听器
  watch: {
    list: {
      immediate: true,
      handler() {
        this.$nextTick(() => {
          /* eslint-disable no-new */
          // 关闭eslint no-new
          new Swiper(this.$refs.mySwiper, {
            loop: true, // 循环模式选项

            // 分页器
            pagination: {
              el: '.swiper-pagination',
              clickable: true
            },

            // 前进后退按钮
            navigation: {
              nextEl: '.swiper-button-next',
              prevEl: '.swiper-button-prev'
            }
          })
        })
      }
    }
  },
  methods: {}
}
</script>

<style lang= 'less' scoped>
</style>
